package com.simple.simple_view.controller.video;

import com.simple.simple_view.domain.ResponseResult;
import com.simple.simple_view.domain.dto.VideoDto;
import com.simple.simple_view.domain.enums.AppHttpCodeEnum;
import com.simple.simple_view.exception.SystemException;
import com.simple.simple_view.service.VideoService;
import javax.annotation.Resource;

import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

/*
 *@description: 视频相关功能
 *@author: hisen
 *@Time: 2023/10/26  16:14
 */
@RestController
@RequestMapping("/video")
public class VideoController {
    @Resource
    VideoService videoService;
    @PostMapping("/upload")
    public ResponseResult uploadVideo(@ModelAttribute VideoDto videoDto) throws Exception {
        if(!StringUtils.hasText(videoDto.getText()))
        {
            throw new SystemException(AppHttpCodeEnum.VIDEO_TEXT_NOT_NULL);
        }
        if(videoDto.getCategory()==null)
        {
            throw new SystemException(AppHttpCodeEnum.VIDEO_CATEGORY_NOT_NULL);
        }
        if(videoDto.getVideoFile()==null)
        {
            throw new SystemException(AppHttpCodeEnum.VIDEO_NOT_NULL);
        }
        return videoService.uploadVideo(videoDto);
    }
    @GetMapping("/page")
    public ResponseResult getVideoPage(@RequestParam int currentPage,@RequestParam int pageSize){
        return videoService.getVideoPage(currentPage,pageSize);
    }
    @GetMapping("/videoInfo")
    public ResponseResult getVideoInfo(@RequestParam int videoId){
        return videoService.getVideoInfo(videoId);
    }
}
